/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */





package Model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author ngoc
 */
public class DataSource {
    Connection connection;
    public Connection getconnectToMSSQL()
    {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
                connection = DriverManager.getConnection("jdbc:sqlserver://localhost:6965;database=PROGRAMLEARNINGIELTS;User=sa;Password=123456;");
            } catch (SQLException ex1) {
                Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex1);
            }
        return connection;
    }
    public void Close()
    {
        if(connection!=null)
            try {
                if(!connection.isClosed())
                    connection.close();
        } catch (SQLException ex) {
            Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
        }
        connection=null;
    }
}
